package com.webserver.core;

import com.webserver.http.HttpServletRequest;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liyang
 * @version 1.0
 * @package com.webserver.core
 * @file ClientHandler.java
 * @description
 * @time 2024-04-30 15:14
 */

/*线程不再需要共享数据，也就不再需要定义为内部类了
* 这是一个线程任务➡实现接口*/
public class ClientHandler implements Runnable{
    private Socket socket;
    public ClientHandler(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run(){
        try {
            //1解析请求
            HttpServletRequest request = new HttpServletRequest(socket);
            //下面注释掉的代码为刚整合好 request方法后的测试环节

            /*String method = request.getMethod();
            System.out.println(method);
            String header = request.getHeader("host");
            System.out.println("host是:"+ header);*/




            //2处理请求







            //3发送响应


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //一问一答后断开TCP连接
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    //    读消息头：又要读一行，读一行，读一行...➡干脆写成方法来实现复用
    //    throws:被重用的代码有异常都不自己处理,都是抛出去的

}